<?php
session_start();
$userid=$_SESSION['userid'];
include ('mysqli_connect.php');
$xgid=$_GET['id'];

$sqlb="SELECT `movie_information_table`.`movie_id`,
`movie_information_table`.`movie_director`,
`movie_information_table`.`movie_regiou`,
`movie_information_table`.`release_time`,
`movie_information_table`.`movie_language`,
`movie_information_table`.`movie_duration`,
`movie_information_table`.`movie_Chinese_name`,
`movie_information_table`.`movie_English_name`,
`movie_information_table`.`movie_marking`,
`movie_information_table`.`movie_intro`
FROM `movie_information_table`
where movie_id={$xgid};";
$resb=mysqli_query($dbc,$sqlb);
$resultb=mysqli_fetch_array($resb);

$sql_temp="SELECT `movie_classification_table`.`classification`,
`movie_classification_table`.`movie_id`
FROM `movie_classification_table`
where movie_id='{$xgid}';";
$res_temp=mysqli_query($dbc,$sql_temp);
$classification='';
while($row_temp=mysqli_fetch_assoc($res_temp))
{
    $classification = $classification.$row_temp['classification'];
    $classification = $classification." ";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <title>影视信息修改</title>
</head>
<body>
    <h1 style="text-align: center"><strong>影视信息修改</strong></h1>
    <div style="padding: 10px 500px 10px;">
    <form  action="admin_movie_edit.php?id=<?php echo $xgid; ?>"" method="POST" style="text-align: center" class="bs-example bs-example-form" role="form">
    <div id="login">
        <div class="input-group"><span  class="input-group-addon">导演</span><input value="<?php echo $resultb['movie_director']; ?>" name="nauthor" type="text" placeholder="请输入修改的导演" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">地区</span><input value="<?php echo $resultb['movie_regiou']; ?>"  name="npublish" type="text" placeholder="请输入修改的地区" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">上映时间</span><input value="<?php echo $resultb['release_time']; ?>" name="nISBN" type="text" placeholder="请输入修改的上映时间" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">语言</span><input  value="<?php echo $resultb['movie_language']; ?>" name="nintroduction" type="text" placeholder="请输入修改的语言" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">时长</span><input value="<?php echo $resultb['movie_duration']; ?>" name="nlanguage" type="text" placeholder="请输入修改的时长" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">分类</span><input value="<?php echo $classification; ?>" name="nclass" type="text" placeholder="请输入修改的分类" class="form-control"></div><br/>
        <div class="input-group"><span class="input-group-addon">中文名</span><input value="<?php echo $resultb['movie_Chinese_name']; ?>" name="nprice" type="text" placeholder="请输入修改的中文名" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">英文名</span><input value="<?php echo $resultb['movie_English_name']; ?>" name="npubdate" type="text" placeholder="请输入修改的英文名" class="form-control"></div><br/>
        <div class="input-group"><span class="input-group-addon">平均评分</span><input  value="<?php echo $resultb['movie_marking']; ?>" name="nclass_id" type="text" placeholder="请输入修改的平均评分" class="form-control"></div><br/>
        <div class="input-group"><span  class="input-group-addon">简介</span><input value="<?php echo $resultb['movie_intro']; ?>" name="npressmark" type="text" placeholder="请输入修改的简介" class="form-control"></div><br/>
        <label><input type="submit" value="确认" class="btn btn-default"></label>
        <label><input type="reset" value="重置" class="btn btn-default"></label>
    </div>
    </form>
    </div>
</body>

<?php


    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
    
        $boid=$_GET['id'];
        //$nnam = $_POST["nname"];
        $naut = $_POST["nauthor"];
        $npubl = $_POST["npublish"];
        $nisb = $_POST["nISBN"];
        $nint = $_POST["nintroduction"];
        $nlan = $_POST["nlanguage"];
        $npri = $_POST["nprice"];
        $npubd = $_POST["npubdate"];
        $ncla = $_POST["nclass_id"];
        $npre = $_POST["npressmark"];
        $nclass = $_POST["nclass"];
        //$nsta= $_POST["nstate"];
        //修改分类数据
        $sqlb_1 = "delete from movie_classification_table where movie_id='{$boid}';";
        $resb_1 = mysqli_query($dbc,$sqlb_1);
        if($resb_1 == 1)
        {
            $class_arr=explode(" ",$nclass);
            for ($i=0;$i<count($class_arr);$i++)
            {
                $sqlb_2 = "INSERT INTO `movie_classification_table`(`classification`,`movie_id`) VALUES('{$class_arr[$i]}','{$boid}');";
                $resb_2 = mysqli_query($dbc,$sqlb_2);
                if($resb_2!=1)
                {
                    echo "<script>alert('插入失败！')</script>";
                }
            }
            
        }
        else{
            echo "<script>alert('删除失败！')</script>";
        }

        //修改影视信息数据
        $sqla="update movie_information_table set movie_director='{$naut}',movie_regiou='{$npubl}',
        release_time='{$nisb}',movie_language='{$nint}',movie_duration={$nlan},movie_Chinese_name='{$npri}',movie_English_name='{$npubd}',
        movie_marking={$ncla},movie_intro='{$npre}' where movie_id={$boid};";
        $resa=mysqli_query($dbc,$sqla);
        
        if($resa==1)
        {
            echo "<script>alert('修改成功！')</script>";
            #echo "<script>window.location.href='admin_book.php'</script>";
        }
        else
        {
            #echo "<script>alert('修改失败！请重新输入！');</script>";
    
        }
    
    }




?>
</body>
</html>
